package cn.com.backstage.controller.base;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.api.entity.ApiT_member_task_process;

import cn.com.api.service.ApiT_member_task_processService;

import cn.com.util.*;


public class T_member_task_processBaseController {

	private static Logger logger = Logger.getLogger(T_member_task_processBaseController.class);
	
	@Autowired
	private ApiT_member_task_processService apiT_member_task_processService;
	
	/**
	 * 列表
	 * @return
	 */
	@RequestMapping(value = "t_member_task_process-list")
	public ModelAndView t_member_task_process_list(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/t_member_task_process_list.jsp");
		
		List<ApiT_member_task_process> t_member_task_processs = apiT_member_task_processService.findT_member_task_processs();
		mv.addObject("t_member_task_processs", t_member_task_processs);
		
		return mv;
	}
	
	/**
	 * 进入新增或者编辑页面
	 * @return
	 */
	@RequestMapping(value = "t_member_task_process-add-pre")
	public ModelAndView t_member_task_process_add_pre(HttpServletRequest request, HttpServletResponse response) throws Exception{
		ModelAndView mv = new ModelAndView("forward:/backstage/t_member_task_process_add.jsp");
		//
		if(request.getParameter("id")!=null){
			String id = request.getParameter("id");
			ApiT_member_task_process t_member_task_process = apiT_member_task_processService.findT_member_task_processById(Integer.valueOf(id));
			mv.addObject("t_member_task_process",t_member_task_process);
		}
		return mv;
	}

	/**
	 *新增或者编辑
	 * @return
	 */
	@RequestMapping(value = "t_member_task_process-add")
	public void t_member_task_process_add(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String process_id = request.getParameter("process_id");
		String user_id = request.getParameter("user_id");
		String task_id = request.getParameter("task_id");
		String dead_time = request.getParameter("dead_time");
		String curr_partner_count = request.getParameter("curr_partner_count");
		String curr_ent_count = request.getParameter("curr_ent_count");
		String curr_advert_money = request.getParameter("curr_advert_money");
		String frozen_money = request.getParameter("frozen_money");
		
		Map<String,Object> map = new HashMap<String,Object>();
		//String id = request.getParameter("id");
		//add
		if(process_id==null || (process_id.trim()).equals("")){
			ApiT_member_task_process t_member_task_process = new ApiT_member_task_process();
            /*
		    t_member_task_process.setProcess_id(process_id);
		    t_member_task_process.setUser_id(user_id);
		    t_member_task_process.setTask_id(task_id);
		    t_member_task_process.setDead_time(dead_time);
		    t_member_task_process.setCurr_partner_count(curr_partner_count);
		    t_member_task_process.setCurr_ent_count(curr_ent_count);
		    t_member_task_process.setCurr_advert_money(curr_advert_money);
		    t_member_task_process.setFrozen_money(frozen_money);
	        */
			apiT_member_task_processService.insertT_member_task_process(t_member_task_process);
		}
		//edit
		else{
			ApiT_member_task_process t_member_task_process = apiT_member_task_processService.findT_member_task_processById(Integer.valueOf(process_id));
	        /*
		    t_member_task_process.setProcess_id(process_id);
		    t_member_task_process.setUser_id(user_id);
		    t_member_task_process.setTask_id(task_id);
		    t_member_task_process.setDead_time(dead_time);
		    t_member_task_process.setCurr_partner_count(curr_partner_count);
		    t_member_task_process.setCurr_ent_count(curr_ent_count);
		    t_member_task_process.setCurr_advert_money(curr_advert_money);
		    t_member_task_process.setFrozen_money(frozen_money);
			*/
			apiT_member_task_processService.updateT_member_task_process(t_member_task_process);
		}
		//
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put(Utils.MESSAGE, "添加成功！");
        JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
	/**
	 *删除
	 * @return
	 */
	@RequestMapping(value = "t_member_task_process-delete")
	public void t_member_task_process_delete(HttpServletRequest request, HttpServletResponse response) throws Exception{
		
		Map<String,Object> map = new HashMap<String,Object>();
		String id = request.getParameter("id");
		
		//delete
		int ret_i =	apiT_member_task_processService.deleteT_member_task_process(Integer.valueOf(id));
		
		//
		if(ret_i > 0){
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "删除成功！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
}



